Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
How to fill a input type="file" through only Javascript?

I'm trying to fill a form and submit it using only JS.

For instance, in this page :

<form>
    <input id="yourname" type="text"></input><br/>
    <input id="yourfile" type="file"></input><br/>
    <input type="submit"></input><br/>
</form>

I'm trying to use something like this to submit the form :

document.getElementById('yourname').value = 'Paul';
document.getElementById('yourfile').value = 'c:\users\admin\desktop\myfile.jpg';
document.forms[0].submit();

I know the second line of the script above will throw an exception. Instead, I could click on the input:

document.getElementById('myfile').value = 'Paul';

But this will open a window to select the file, but I can't fill this window using JS... can I?

Is there any workaround for this? Or is the only way to select a file in a web form manually?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

...i can't fill this window using JS... or can i ?

No, you are not able to fill that form through JavaScript.

If you could, it would allow websites to take files from your computer without your knowledge, which would be a huge security violation. That's why it makes a window open on your desktop: so that the user knows that the site is trying to download a file.

[Are there] any [workarounds] for this or the only way to select a file in a web form is manually?

No, there are no workarounds for this feature.

As I said above, it would be a major security issue if you could do this, so the only way to get a file from a user is to use the popup window.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda